package cn.iocoder.yudao.module.handguard.service.userbasetable15;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable15.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable15.UserBaseTable15DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable15.UserBaseTable15Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable15.UserBaseTable15Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 完成住宅抵押 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable15ServiceImpl implements UserBaseTable15Service {

    @Resource
    private UserBaseTable15Mapper userBaseTable15Mapper;

    @Override
    public Long createUserBaseTable15(UserBaseTable15CreateReqVO createReqVO) {
        // 插入
        UserBaseTable15DO userBaseTable15 = UserBaseTable15Convert.INSTANCE.convert(createReqVO);
        userBaseTable15Mapper.insert(userBaseTable15);
        // 返回
        return userBaseTable15.getId();
    }

    @Override
    public void updateUserBaseTable15(UserBaseTable15UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable15Exists(updateReqVO.getId());
        // 更新
        UserBaseTable15DO updateObj = UserBaseTable15Convert.INSTANCE.convert(updateReqVO);
        userBaseTable15Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable15(Long id) {
        // 校验存在
        validateUserBaseTable15Exists(id);
        // 删除
        userBaseTable15Mapper.deleteById(id);
    }

    private void validateUserBaseTable15Exists(Long id) {
        if (userBaseTable15Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE15_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable15DO getUserBaseTable15(Long id) {
        return userBaseTable15Mapper.selectById(id);
    }

    @Override
    public List<UserBaseTable15DO> getUserBaseTable15List(Long userId) {
        LambdaQueryWrapper<UserBaseTable15DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable15DO::getUserId,userId);
        return userBaseTable15Mapper.selectList(queryWrapper);
    }

    @Override
    public PageResult<UserBaseTable15DO> getUserBaseTable15Page(UserBaseTable15PageReqVO pageReqVO) {
        return userBaseTable15Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable15DO> getUserBaseTable15List(UserBaseTable15ExportReqVO exportReqVO) {
        return userBaseTable15Mapper.selectList(exportReqVO);
    }

}
